package com.xintonghua.bussiness.ui.user;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;

import com.xintonghua.base.adapter.BaseFragmentAdapter;
import com.xintonghua.base.ui.BaseActivity;
import com.xintonghua.bussiness.R;
import com.xintonghua.bussiness.ui.user.manage.AddEmployeeActivty;
import com.xintonghua.bussiness.ui.user.manage.AddProductActivity;
import com.xintonghua.bussiness.ui.user.manage.EmployeeManageFragment;
import com.xintonghua.bussiness.ui.user.manage.GoodsManageFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 作者：wanxianyi
 * 时间：2018/1/15.
 * 包名：com.xintonghua.bussiness.ui.user
 */

public class HomeManageActivity extends BaseActivity {
    @BindView(R.id.tab_manage)
    TabLayout tabManage;
    @BindView(R.id.vp_manage)
    ViewPager vpManage;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.iv_add)
    ImageView ivAdd;
    String[] title = new String[]{"员工管理", "商品管理"};
    private List<Fragment> fragmentList = new ArrayList<>();
    private List<String> titleList;
    private BaseFragmentAdapter adapter;
    EmployeeManageFragment employeeManageFragment = new EmployeeManageFragment();
    GoodsManageFragment goodsManageFragment = new GoodsManageFragment();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home_manage);
        ButterKnife.bind(this);
        initUI();
    }

    @Override
    public void initUI() {
        super.initUI();
        titleList = new ArrayList<>();
        for (String s : title) {
            titleList.add(s);
        }
        fragmentList.add(employeeManageFragment);
        fragmentList.add(goodsManageFragment);
        adapter = new BaseFragmentAdapter(getSupportFragmentManager(), fragmentList, titleList);
        vpManage.setAdapter(adapter);
        tabManage.setupWithViewPager(vpManage);
    }

    @OnClick({R.id.iv_back, R.id.iv_add})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.iv_add:
                if (tabManage.getSelectedTabPosition() == 0) {
                    openActivity(AddEmployeeActivty.class);
                } else {
                    openActivity(AddProductActivity.class);
                }
                break;
        }

    }
}
